package org.example.kidscode.service;

import org.example.kidscode.entity.Course;  // 关键修正点！
import org.example.kidscode.repository.CourseRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;

@Service
@Transactional
public class CourseService {

    private final CourseRepository courseRepository;

    @Autowired
    public CourseService(CourseRepository courseRepository) {
        this.courseRepository = courseRepository;
    }

    public List<Course> findAll() {
        return courseRepository.findAll();
    }

    public Optional<Course> findById(String courseId) {
        return courseRepository.findById(courseId);
    }

    public Course save(Course course) {
        return courseRepository.save(course);
    }

    public void deleteById(String courseId) {
        courseRepository.deleteById(courseId);
    }

    public List<Course> findByTeacher(String teacherId) {
        return courseRepository.findByTeacherId(teacherId);
    }

    public List<Course> findByType(String courseType) {
        return courseRepository.findByCourseType(courseType);
    }
}